package com.bird.generate.ddd.adapter.database

import com.bird.component.database.model.richEntity
import com.bird.generate.ddd.adapter.database.dataobj.AggregateRootDO
import com.bird.generate.ddd.adapter.database.dataobj.EntityDO
import com.bird.generate.ddd.adapter.database.dataobj.FieldDO
import com.bird.generate.ddd.adapter.database.dataobj.ValueObjectDO
import com.bird.generate.ddd.domain.AggregateRootEntity
import com.bird.generate.ddd.domain.EntityEntity
import com.bird.generate.ddd.domain.ValueObjectEntity
import com.bird.generate.ddd.domain.vo.Field

fun AggregateRootEntity.toDO(): AggregateRootDO {
    return AggregateRootDO(
        name = this.name,
        description = this.description,
        enName = this.enName,
        version = this.version,
        moduleName = this.moduleName,
        projectName = this.projectName,
        creator = this.creator,
        multiTenant = this.multiTenant,
        comPrefix = this.comPrefix
    ).also { it.richBase(this) }
}

fun AggregateRootDO.toEntity(): AggregateRootEntity {
    return AggregateRootEntity(
        name = this.name,
        description = this.description,
        enName = this.enName,
        version = this.version,
        moduleName = this.moduleName,
        projectName = this.projectName,
        creator = this.creator,
        multiTenant = this.multiTenant,
        comPrefix = this.comPrefix
    ).also { it.richEntity(this) }
}

fun EntityEntity.toDO(rootId:Long): EntityDO {
    return EntityDO(
        name = this.name,
        description = this.description,
        enName = this.enName,
        aggregateRootId = rootId
    ).also { it.richBase(this) }
}

fun EntityDO.toEntity(): EntityEntity {
    return EntityEntity(
        name = this.name,
        description = this.description,
        enName = this.enName,
    ).also { it.richEntity(this) }
}

fun ValueObjectEntity.toDo(rootId:Long): ValueObjectDO {
    return ValueObjectDO(
        name = this.name,
        description = this.description,
        enName = this.enName,
        isEnum = this.isEnum,
        aggregateRootId = rootId
    ).also { it.richBase(this) }
}

fun ValueObjectDO.toEntity(): ValueObjectEntity {
    return ValueObjectEntity(
        name = this.name,
        description = this.description,
        enName = this.enName,
        isEnum = this.isEnum,
    ).also { it.richEntity(this) }
}

fun Field.toDo(parentId: Long): FieldDO {
    return FieldDO(
        name = this.name,
        enName = this.enName,
        type = this.type,
        description = this.description,
        required = this.required,
        toEquals = this.toEquals,
        parentId = parentId,
        sort = this.sort
    )
}

fun FieldDO.toEntity(): Field {
    return Field(
        name = this.name,
        enName = this.enName,
        type = this.type,
        description = this.description,
        required = this.required,
        toEquals = this.toEquals,
        sort = this.sort
    )
}

